$OpenBSD: patch-Source_JavaScriptCore_heap_MachineStackMarker_cpp,v 1.4 2017/05/10 10:57:54 ajacoutot Exp $

XXX no mcontext_t on OpenBSD

Index: Source/JavaScriptCore/heap/MachineStackMarker.cpp
--- Source/JavaScriptCore/heap/MachineStackMarker.cpp.orig
+++ Source/JavaScriptCore/heap/MachineStackMarker.cpp
@@ -88,7 +88,9 @@ static void pthreadSignalHandlerSuspendResume(int, sig
     }
 
     ucontext_t* userContext = static_cast<ucontext_t*>(ucontext);
-#if CPU(PPC)
+#if OS(OPENBSD)
+    threadData->suspendedMachineContext = *userContext;
+#elif CPU(PPC)
     threadData->suspendedMachineContext = *userContext->uc_mcontext.uc_regs;
 #else
     threadData->suspendedMachineContext = userContext->uc_mcontext;
@@ -577,6 +579,24 @@ void* MachineThreads::ThreadData::Registers::stackPoin
 #error Unknown Architecture
 #endif
 
+#elif OS(OPENBSD) && ENABLE(JIT)
+
+#if CPU(X86)
+    return reinterpret_cast<void*>((uintptr_t) regs.machineContext.sc_esp);
+#elif CPU(X86_64)
+    return reinterpret_cast<void*>((uintptr_t) regs.machineContext.sc_rsp);
+#elif CPU(ARM)
+    return reinterpret_cast<void*>((uintptr_t) regs.machineContext.__gregs[_REG_SP]);
+#elif CPU(ARM64)
+    return reinterpret_cast<void*>((uintptr_t) regs.machineContext.mc_gpregs.gp_sp);
+#elif CPU(MIPS)
+    return reinterpret_cast<void*>((uintptr_t) regs.machineContext.mc_regs[29]);
+#elif CPU(SPARC64)
+    return reinterpret_cast<void*>((uintptr_t) regs.machineContext.mc_rsp);
+#else
+#error Unknown Architecture
+#endif
+
 #elif defined(__GLIBC__) && ENABLE(JIT)
 
 #if CPU(X86)
@@ -676,6 +696,24 @@ void* MachineThreads::ThreadData::Registers::framePoin
 #error Unknown Architecture
 #endif
 
+#elif OS(OPENBSD)
+
+#if CPU(X86)
+    return reinterpret_cast<void*>((uintptr_t) regs.machineContext.sc_ebp);
+#elif CPU(X86_64)
+    return reinterpret_cast<void*>((uintptr_t) regs.machineContext.sc_rbp);
+#elif CPU(ARM)
+    return reinterpret_cast<void*>((uintptr_t) regs.machineContext.__gregs[_REG_FP]);
+#elif CPU(ARM64)
+    return reinterpret_cast<void*>((uintptr_t) regs.machineContext.mc_gpregs.gp_x[29]);
+#elif CPU(MIPS)
+    return reinterpret_cast<void*>((uintptr_t) regs.machineContext.mc_regs[30]);
+#elif CPU(SPARC64)
+    return reinterpret_cast<void*>((uintptr_t) regs.machineContext.mc_rbp);
+#else
+#error Unknown Architecture
+#endif
+
 #elif defined(__GLIBC__)
 
 // The following sequence depends on glibc's sys/ucontext.h.
@@ -758,6 +796,24 @@ void* MachineThreads::ThreadData::Registers::instructi
 #error Unknown Architecture
 #endif
 
+#elif OS(OPENBSD)
+
+#if CPU(X86)
+    return reinterpret_cast<void*>((uintptr_t) regs.machineContext.sc_eip);
+#elif CPU(X86_64)
+    return reinterpret_cast<void*>((uintptr_t) regs.machineContext.sc_rip);
+#elif CPU(ARM)
+    return reinterpret_cast<void*>((uintptr_t) regs.machineContext.__gregs[_REG_PC]);
+#elif CPU(ARM64)
+    return reinterpret_cast<void*>((uintptr_t) regs.machineContext.mc_gpregs.gp_elr);
+#elif CPU(MIPS)
+    return reinterpret_cast<void*>((uintptr_t) regs.machineContext.mc_pc);
+#elif CPU(SPARC64)
+    return reinterpret_cast<void*>((uintptr_t) regs.machineContext.mc_rip);
+#else
+#error Unknown Architecture
+#endif
+
 #elif defined(__GLIBC__)
 
 // The following sequence depends on glibc's sys/ucontext.h.
@@ -846,6 +902,24 @@ void* MachineThreads::ThreadData::Registers::llintPC()
     return reinterpret_cast<void*>((uintptr_t) regs.machineContext.mc_gpregs.gp_x[4]);
 #elif CPU(MIPS)
     return reinterpret_cast<void*>((uintptr_t) regs.machineContext.mc_regs[12]);
+#else
+#error Unknown Architecture
+#endif
+
+#elif OS(OPENBSD)
+
+#if CPU(X86)
+    return reinterpret_cast<void*>((uintptr_t) regs.machineContext.sc_esi);
+#elif CPU(X86_64)
+    return reinterpret_cast<void*>((uintptr_t) regs.machineContext.sc_r8);
+#elif CPU(ARM)
+    return reinterpret_cast<void*>((uintptr_t) regs.machineContext.__gregs[_REG_R8]);
+#elif CPU(ARM64)
+    return reinterpret_cast<void*>((uintptr_t) regs.machineContext.mc_gpregs.gp_x[4]);
+#elif CPU(MIPS)
+    return reinterpret_cast<void*>((uintptr_t) regs.machineContext.mc_regs[12]);
+#elif CPU(SPARC64)
+    return reinterpret_cast<void*>((uintptr_t) regs.machineContext.mc_r8);
 #else
 #error Unknown Architecture
 #endif
